#include <ptgui/ptgui.h>
#include <ptgui/pagectl.h>
#include <ptgui/pages/page.h>
#include <SDL/SDL.h>

/*	Event Process Table	*/
static	void ptgui_page_entry_handler(ptgui_page_entry_type_t Requese)
{
	if (PTGUI_PAGE_PREPARE_FST == Requese) {
		//Do Nothing
	}
	else if (PTGUI_PAGE_PREPARE_ALL == Requese) {
	}
	else if (PTGUI_PAGE_TERMINATE_ALL == Requese) {
		//Do Nothing
	}
	else if (PTGUI_PAGE_TERMINATE_LST == Requese) {
	}
	else {
		//Do Nothing
	}
}

static	ptgui_page_control_t nvdProcPsvUpdateEndCancel(pt_message_t *EventCode)
{
	return	PTGUI_PAGE_TRAN_RETURN_REQUEST(FP_PAGE_BOOT);
}

static	ptgui_page_sw_state_t nusGetViewPsvUpdateEndCancel(ptgui_page_switch_view_t *Switch)
{
	return	PAGE_SW_STAT_VISIBLE;
}
extern void DrawPict(SDL_Surface *screen, char *bmpfile,
					int speedy, int flip, int nofade);
extern SDL_Surface *screen;
extern int speedy, flip, nofade;
static ptgui_page_control_t ptgui_page_render_handler(pt_message_t* message)
{
	//SDL_FillRect(screen, NULL , SDL_MapRGB(screen->format, 255, 255, 255));

	DrawPict(screen, "sample.bmp", speedy, flip, nofade);

	return PTGUI_PAGE_TRAN_KEEP_FLAT;
}

static ptgui_page_control_t ptgui_page_frame_handler(pt_message_t* message)
{
	return PTGUI_PAGE_TRAN_KEEP_FLAT;
}

static ptgui_page_control_t ptgui_page_mouse_handler(pt_message_t* message)
{
	ptgui_page_key_event_break();
	return PTGUI_PAGE_TRAN_CALL_REQUEST(FP_PAGE_DRAW);
}
/*	Opening Cancel Key Definition	*/
PTGUI_PAGE_DEF_SW_VIEW(TswPsvUpdateEndCancel, nvdProcPsvUpdateEndCancel, nusGetViewPsvUpdateEndCancel, 0, 0, 0,
					   (KEY_ON_DO));

/*	Static Key Table	*/
PTGUI_PAGE_BEGIN_REF_SW_VIEW_TABLE 
PTGUI_PAGE_REF_SW_VIEW(TswPsvUpdateEndCancel),
PTGUI_PAGE_END_REF_SW_VIEW_TABLE(FP_PAGE_BOOT);

PTGUI_PAGE_BEGIN_DEF_EVENT_ACCEPT 
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_RENDER, ptgui_page_render_handler),
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_FRAME, ptgui_page_frame_handler),
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_MOUSE_BUTTON, ptgui_page_mouse_handler),
PTGUI_PAGE_END_DEF_EVENT_ACCEPT;

PTGUI_PAGE_DEF_PAGECELL(FP_PAGE_BOOT);